package de.tabreaderandroid.tabreader.model;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import de.tabreaderandroid.tabreader.R;
import de.tabreaderandroid.tabreader.activities.TabListActivity;

/**
 * {@link ArrayAdapter} to show the files in the list in the
 * {@link TabListActivity}.
 * 
 * @author André Stannek
 * 
 */
public class TabListAdapter extends ArrayAdapter<TabListItem> {

	/**
	 * Constructs a new Adapter with a context.
	 * 
	 * @param context
	 * @see ArrayAdapter#ArrayAdapter(Context, int)
	 */
	public TabListAdapter(Context context) {
		super(context, R.layout.listview_item_tablist);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View rowView = convertView;
		if (rowView == null) {
			LayoutInflater inflater = ((Activity) getContext())
					.getLayoutInflater();
			rowView = inflater.inflate(R.layout.listview_item_tablist, parent,
					false);
		}
		TextView titleView = (TextView) rowView.findViewById(R.id.txtSongTitle);
		TextView pathView = (TextView) rowView.findViewById(R.id.txtSongPath);

		TabListItem item = getItem(position);
		titleView.setText(item.getSongName());
		pathView.setText(item.getPath());

		return rowView;
	}
}
